package com.myk.game.heroscuffle.heroes;

import com.myk.game.heroscuffle.game.Attacked;
import com.myk.game.heroscuffle.game.Element;
import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.Skill;
import com.myk.game.heroscuffle.signs.TimeSign_DuChong;
import com.myk.game.heroscuffle.skills.Skill_GuiChao;
import com.myk.game.heroscuffle.utils.RdmPropUtil;
import com.myk.game.heroscuffle.utils.Weighter;
import com.myk.game.heroscuffle.utils.WeighterTask;

public class Hero_ChiLian extends Hero {

    public Hero_ChiLian() {
        super("赤炼",
                "被自己攻击过的英雄和攻击了自己的敌人都会被种下毒虫持续2回合，中毒者每回合开始都会受到一定伤害。",
                Element.FLAME,
                1180, 148, 46,
                new Skill_GuiChao());
    }

    @Override
    public void onAutoSelectAction() {
        Hero anther = game.pool.getAnyoneAliveHero(this, state.getAliveEnemy(), state.getAlivePrey()); //获取新目标
        boolean isLowHp = hp < (HP / 2f); //是否残血
        int signCount = game.pool.getAllAliveHeroesBy(item -> item.hasSign(TimeSign_DuChong.class)).size(); //全场毒虫数量
        Skill skill = getUsableSkill(Skill_GuiChao.class); //获取技能

        Runnable useSkill = () -> useSkill(skill); //使用主动技归巢的行为
        Runnable attackAnther = () -> doAttackActionStart(new Attacked(anther, "新觅毒皿偷袭")); //对新目标普攻的行为
        Runnable defaultAction = super::onAutoSelectAction; //默认行为

        if (anther != null) {
            if (isLowHp) {
                if (signCount != 0) {
                    if (skill != null) {
                        RdmPropUtil.lotteryExecute(new WeighterTask(7, useSkill), new WeighterTask(3, attackAnther), new WeighterTask(1, defaultAction));
                    }
                    else {
                        RdmPropUtil.lotteryExecute(new WeighterTask(3, attackAnther), new WeighterTask(1, defaultAction));
                    }
                }
                else {
                    RdmPropUtil.lotteryExecute(new WeighterTask(4, attackAnther), new WeighterTask(1, defaultAction));
                }
            }
            else {
                if (signCount != 0) {
                    if (skill != null) {
                        RdmPropUtil.lotteryExecute(new WeighterTask(2, useSkill), new WeighterTask(3, attackAnther), new WeighterTask(1, defaultAction));
                    }
                    else {
                        RdmPropUtil.lotteryExecute(new WeighterTask(3, attackAnther), new WeighterTask(1, defaultAction));
                    }
                }
                else {
                    RdmPropUtil.lotteryExecute(new WeighterTask(4, attackAnther), new WeighterTask(1, defaultAction));
                }
            }
        }
        else {
            if (isLowHp) {
                if (signCount != 0) {
                    if (skill != null) {
                        RdmPropUtil.lotteryExecute(new WeighterTask(5, useSkill), new WeighterTask(1, defaultAction));
                    }
                    else {
                        RdmPropUtil.lotteryExecute(new WeighterTask(1, defaultAction));
                    }
                }
                else {
                    RdmPropUtil.lotteryExecute(new WeighterTask(1, defaultAction));
                }
            }
            else {
                if (signCount != 0) {
                    if (skill != null) {
                        RdmPropUtil.lotteryExecute(new WeighterTask(2, useSkill), new WeighterTask(3, defaultAction));
                    }
                    else {
                        RdmPropUtil.lotteryExecute(new WeighterTask(1, defaultAction));
                    }
                }
                else {
                    RdmPropUtil.lotteryExecute(new WeighterTask(1, defaultAction));
                }
            }
        }
    }

    @Override
    public void onAfterDoAttack(Hero attacked, int damage, boolean isToDeath) {
        if (!isToDeath) {
            attacked.pasteSign(new TimeSign_DuChong());
        }
    }

    @Override
    public void onAfterBeAttack(Hero attacker, int damage) {
        attacker.pasteSign(new TimeSign_DuChong());
    }

}
